#include <iostream>
#include <cstring>
#include <queue>
using namespace std;
struct Node
{
	Node(int n,int m):pos(n),step(m){}
	Node(const Node &node):pos(node.pos),step(node.step){}
	int pos;
	int step;
};
int visited[200000];
int man, cow;

int sol()
{
	queue<Node> q;
	q.push(Node(man, 0));
	memset(visited, 0, sizeof(visited));
	visited[man] = 1;
	while(!q.empty())
	{
		Node now = q.front();
		if (now.pos == cow)
			return now.step;
		q.pop();
		for(int i=0;i<3;++i)
		{
			Node next = now;
			switch (i)
			{
			case 0:
				next.pos++;
				break;
			case 1:
				next.pos--;
				break;
			case 2:
				next.pos *= 2;
				break;
			default: ;
			}
			next.step++;
			if (next.pos == cow)
				return next.step;

			if(next.pos>=0 && next.pos<=200000 && !visited[next.pos])
			{
				visited[next.pos] = 1;
				q.push(next);
			}
		}
	}
	return 0;
}

int main()
{
	while (cin >> man >> cow)
	{
		if (man != cow)
		{
			if ( man * 2 == cow||man+1==cow)
				cout << 1 << endl;
			else 
				cout << sol() << endl;
		}
		else
		{
			cout << 0 << endl;
		}
	}
}